import java.util.Scanner;

public class Java013 {
    public static void main(String[] args) {
        int i,n,m;
        Scanner sc=new Scanner(System.in);
        System.out.println("Input: n and m");
        n=sc.nextInt();
        m=sc.nextInt();
        double num1=0,num2;
        for(i=0;i<100000;i++){
            num1=Math.sqrt(i+n);
            num2=Math.sqrt(i+m);
            if(num1==(int)num1&&num2==(int)num2){
                System.out.println(i);
                break;
            }
        }
    }
}
